package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.CardZBBean;

import java.util.List;

public class OilCardAdapter extends ViewHolderRecyclerAdapter<CardZBBean.CardKindDTOsBean> {
    private int pos = -1;

    public OilCardAdapter(Context context, List<CardZBBean.CardKindDTOsBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_oilcar, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper, CardZBBean.CardKindDTOsBean bean, int positions) {
        TextView priceChb = helper.getView(R.id.item_price_btn);
        ImageView llBg = helper.getView(R.id.ll_bg);
        String number = bean.getName();
        String oilType = bean.getProductId();
        if ("1".equals(oilType)) {
            String content = number + "";
            priceChb.setText(content);
            llBg.setImageResource(R.mipmap.member_oils_c);
        } else if ("2".equals(oilType)) {
            String content = number + "";
            priceChb.setText(content);
            llBg.setImageResource(R.mipmap.member_oils_q);
        } else {
            String content = number + "";
            priceChb.setText(content);
            llBg.setImageResource(R.mipmap.member_oils_lng);
        }
        if (pos != -1) {
            if (pos == positions) {
                if ("1".equals(oilType)) {
                    llBg.setImageResource(R.mipmap.member_oils_c);
                } else if ("2".equals(oilType)) {
                    llBg.setImageResource(R.mipmap.member_oils_q);
                } else {
                    llBg.setImageResource(R.mipmap.member_oils_lng);
                }
            } else {
                llBg.setImageResource(R.mipmap.kaikanoselect);
            }
        }


    }

    public void setPos(int pos) {
        this.pos = pos;
        notifyDataSetChanged();
    }

}
